<?php
 If (IsSet ($_GET ["sortie"]) And ($_GET ["sortie"] == 3))
  {
   Echo "<HTML><HEAD><SCRIPT> window.open (\"./index.php?login=1&sortie=3\", \"_top\", \"\") </SCRIPT></HEAD></HTML>" ;
  }
 Else
  {
   Session_Start () ;
   Include ("./inclus/config.inc") ;
   Include_Once ("./include/init.php") ;
   If (IsSet ($_SESSION ["code"]))
    {
     $resultat = SQL_commande ("DELETE FROM sessions WHERE id_session='".$_SESSION ["code"]."' LIMIT 1", $id_sql) ;
     If ($debug_journal == 1)
      {
       Switch ($type_bdd)
        {
         Case "MySQL"      : $ok = @MySQL_Query ("INSERT INTO journal (texte,script,date,adresse) VALUES ('".Session_Id()."','--FIN-SESSION--','".Date ("Y-m-d H:i:s")."','".$_SERVER ["REMOTE_ADDR"]."')", $id_sql) ;
		             Break ;;
         Case "mSQL"       : $ok = @mSQL_Query ("INSERT INTO journal (texte,script,date,adresse) VALUES ('".Session_Id()."','--FIN-SESSION--','".Date ("Y-m-d H:i:s")."','".$_SERVER ["REMOTE_ADDR"]."')", $id_sql) ;
                             Break ;;
         Case "PostgreSQL" : $ok = @PG_Query ($id_sql,"INSERT INTO journal (texte,script,date,adresse) VALUES ('".Session_Id()."','--FIN-SESSION--','".Date ("Y-m-d H:i:s")."','".$_SERVER ["REMOTE_ADDR"]."')") ;
                             Break ;;
         Default           : $ok = @MySQL_Query ("INSERT INTO journal (texte,script,date,adresse) VALUES ('".Session_Id()."','--FIN-SESSION--','".Date ("Y-m-d H:i:s")."','".$_SERVER ["REMOTE_ADDR"]."')", $id_sql) ;
                             Break ;;
        }
      }
     $ok = SQL_fermeture ($id_sql) ;
    }
   @UnLink ("./tmp/f".Session_Id ().".pdf") ;
   @UnLink ("./tmp/f".Session_Id ().".csv") ;
   @UnLink ("./tmp/f".Session_Id ()."*") ;
   $_SESSION = Array () ;
   Session_Destroy () ;
   // Sortie a partir d'un popup
   If (IsSet ($_GET ["fenetre"]) And ($_GET ["fenetre"] == 1))
    {
     Echo "<HTML><HEAD><SCRIPT> window.open (\"".$_SERVER ["PHP_SELF"]."?sortie=".$_GET ["erreur"]."\", \"" ;
     If ($_GET ["droit_courant"] != $droit_prof) { Echo "travail_affichage_3" ; } Else { Echo "travail_affichage" ; }
     Echo "\", \"\");window.close() </SCRIPT></HEAD></HTML>" ;
    }
   Else
    {
     If (IsSet ($_GET ["erreur"]))
      {
       //Header ("Location: ".$page_premiere."?sortie=".$_GET ["erreur"]."&login=1") ; 
       Echo "<HTML><HEAD><SCRIPT> window.open (\"./index.php?login=1&sortie=".$_GET ["erreur"]."\", \"_top\", \"\") </SCRIPT></HEAD></HTML>" ;
      }
     Else
      {
       //Header ("Location: ".$page_premiere."?login=1") ;
       Echo "<HTML><HEAD><SCRIPT> window.open (\"./index.php?login=1\", \"_top\", \"\") </SCRIPT></HEAD></HTML>" ;
      }
    }
  }
?>